home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Hyper / U-Z / UPSCHGS.cpt / UPS_Charge.c next >
Encoding:
C/C++ Source or Header  |  1988-11-24  |  10.1 KB  |  293 lines  |  [TEXT/KAHL]

  1. /* UPS_Charge.c */
  2.  
  3. /*    UPS_Charge XFCN for HyperCard
  4.     with LightSpeedC v. 3.01 - 11/22/88
  5.                                                     Copyright 1988 by
  6.     Given a valid UPS zone and package weight,        Sam Thornton
  7.     returns the correct UPS freight charge.            PO Box 123
  8.     Also supports Federal Express rate chart.        Fairfield NE 68938
  9.     (Rates as of 11/88.)                            Some portions Copyright
  10.                                                     by Symantec and Apple.
  11.     See UPS_Charge.docs for user interface
  12.                                                     Compuserve: 71750,667
  13.                                                     GEnie: S.THORNTON5
  14.                                                     
  15.     NOTE:  All 'StringPtr' types in                    May be copied and
  16.            HyperXCmd.h and glue should                distributed for personal
  17.            be dereferenced to type 'Ptr'            use without charge only,
  18.            for this to compile properly.            except for nominal
  19.                                                     distribution fees. For
  20.                                                     commercial use or
  21.                                                     distribution, contact
  22.                                                     author, above.     */
  23. #include "HyperXCmd.h"
  24. #include "SetUpA4.h"
  25. #include "MemoryMgr.h"
  26. #include "Math.h"
  27. #include "strings.h"
  28. #include "stdio.h"
  29. #include "ctype.h"
  30. #include "unix.h"
  31.  
  32. typedef struct _chgs {
  33.     int    _charge[71]; /* item 1 is reference code/zone, remaining 70 for weights */
  34.     } _chgs;
  35.     
  36. static _chgs charge_table[] = {
  37.  
  38. /* rates are stored as whole numbers, formatted later for return */
  39.  
  40. 0, /* FEDERAL EXPRESS OVERNIGHT */
  41. 2025, 2300, 2575, 2850, 3125, 3400, 3675, 3950,
  42. 4225, 4500, 4625, 4750, 4875, 5000, 5125, 5250,
  43. 5375, 5500, 5625, 5750, 5875, 6000, 6125, 6250,
  44. 6375, 6500, 6625, 6750, 6875, 7000, 7125, 7250,
  45. 7375, 7500, 7625, 7750, 7875, 8000, 8125, 8250,
  46. 8375, 8500, 8625, 8750, 8875, 9000, 9125, 9250,
  47. 9375, 9500, 9625, 9750, 9875, 10000, 10125, 10250,
  48. 10375, 10500, 10625, 10750, 10875, 11000, 11125,
  49. 11250, 11375, 11500, 11625, 11750, 11875, 12000,
  50.  
  51. 1, /* FEDERAL EXPRESS 2ND DAY AIR */
  52. 1150, 1250, 1350, 1450, 1550, 1650, 1750, 1850,
  53. 1950, 2050, 2150, 2250, 2350, 2450, 2550, 2650,
  54. 2750, 2850, 2950, 3050, 3150, 3250, 3350, 3450,
  55. 3550, 3650, 3750, 3850, 3950, 4050, 4150, 4250,
  56. 4350, 4450, 4550, 4650, 4750, 4850, 4950, 5050,
  57. 5150, 5250, 5350, 5450, 5500, 5550, 5600, 5650,
  58. 5700, 5750, 5800, 5850, 5900, 5950, 6000, 6050,
  59. 6100, 6150, 6200, 6250, 6300, 6350, 6400, 6450,
  60. 6500, 6550, 6600, 6650, 6700, 6750,
  61.  
  62. 2, /* UPS SURFACE */
  63. 134, 136, 144, 153, 162, 171, 180, 189, 198,
  64. 207, 216, 225, 234, 243, 252, 261, 270, 279,
  65. 288, 297, 306, 315, 324, 333, 342, 351, 360,
  66. 369, 378, 387, 395, 403, 411, 419, 427, 435,
  67. 443, 451, 459, 467, 475, 483, 491, 499, 507,
  68. 515, 523, 531, 539, 547, 550, 553, 556, 559,
  69. 562, 565, 568, 571, 574, 577, 580, 583, 586,
  70. 589, 592, 595, 598, 601, 604, 607,
  71.  
  72. 3, /* UPS SURFACE */
  73. 145, 147, 160, 172, 183, 192, 204, 216, 229,
  74. 241, 255, 268, 280, 293, 305, 318, 331, 343,
  75. 357, 369, 382, 395, 407, 420, 432, 445, 459,
  76. 471, 484, 496, 513, 530, 542, 556, 568, 581,
  77. 595, 607, 620, 632, 646, 659, 671, 685, 697,
  78. 710, 724, 736, 749, 762, 766, 769, 772, 775,
  79. 778, 781, 785, 788, 791, 794, 797, 801, 804,
  80. 808, 811, 814, 817, 820, 823, 826,
  81.  
  82. 4, /* UPS SURFACE */
  83. 160, 179, 194, 211, 222, 233, 249, 267, 284,
  84. 300, 317, 334, 351, 369, 385, 402, 419, 436,
  85. 453, 470, 487, 504, 521, 538, 554, 572, 589,
  86. 606, 623, 639, 662, 684, 701, 719, 735, 752,
  87. 770, 787, 805, 821, 838, 856, 873, 891, 907,
  88. 925, 942, 959, 977, 993, 998, 1002, 1008, 1012,
  89. 1016, 1021, 1025, 1029, 1034, 1038, 1042, 1048,
  90. 1052, 1056, 1061, 1065, 1069, 1074, 1078, 1082,
  91.  
  92. 5, /* UPS SURFACE */
  93. 167, 190, 211, 231, 246, 263, 283, 305, 326,
  94. 347, 370, 391, 413, 434, 456, 478, 499, 521,
  95. 542, 564, 586, 607, 629, 650, 672, 694, 715,
  96. 737, 759, 780, 809, 835, 858, 879, 901, 924,
  97. 945, 968, 989, 1011, 1033, 1055, 1077, 1099,
  98. 1120, 1143, 1164, 1187, 1208, 1230, 1236, 1241,
  99. 1247, 1253, 1259, 1264, 1269, 1275, 1280, 1286,
  100. 1292, 1298, 1303, 1308, 1314, 1319, 1325, 1330,
  101. 1337, 1342,
  102.  
  103. 6, /* UPS SURFACE */
  104. 174, 205, 232, 260, 281, 302, 329, 358, 386,
  105. 413, 441, 470, 498, 526, 553, 582, 610, 638,
  106. 667, 694, 722, 750, 779, 807, 834, 863, 891,
  107. 919, 947, 975, 1011, 1047, 1075, 1104, 1132,
  108. 1160, 1189, 1218, 1246, 1274, 1303, 1331, 1360,
  109. 1389, 1417, 1445, 1474, 1503, 1531, 1559, 1566,
  110. 1573, 1581, 1588, 1595, 1602, 1609, 1616, 1624,
  111. 1630, 1637, 1644, 1651, 1658, 1666, 1673, 1680,
  112. 1687, 1694, 1700,
  113.  
  114. 7, /* UPS SURFACE */
  115. 183, 220, 255, 289, 317, 344, 378, 412, 447,
  116. 482, 517, 551, 587, 621, 657, 691, 726, 781,
  117. 796, 830, 866, 900, 935, 970, 1005, 1039, 1075,
  118. 1109, 1144, 1179, 1224, 1267, 1303, 1338, 1374,
  119. 1408, 1444, 1479, 1515, 1550, 1586, 1621, 1656,
  120. 1691, 1727, 1762, 1798, 1833, 1869, 1903, 1913,
  121. 1922, 1931, 1940, 1950, 1959, 1968, 1977, 1986,
  122. 1996, 2005, 2014, 2023, 2033, 2042, 2051, 2060,
  123. 2069, 2079, 2088,
  124.  
  125. 8, /* UPS SURFACE */
  126. 191, 237, 278, 320, 354, 388, 428, 470, 512,
  127. 553, 596, 638, 680, 722, 764, 806, 848, 890,
  128. 932, 974, 1016, 1058, 1100, 1142, 1184, 1226,
  129. 1269, 1310, 1352, 1394, 1448, 1501, 1543, 1586,
  130. 1628, 1671, 1714, 1756, 1799, 1841, 1884, 1927,
  131. 1969, 2012, 2054, 2097, 2140, 2182, 2225, 2267,
  132. 2279, 2289, 2299, 2310, 2321, 2331, 2342, 2352,
  133. 2363, 2374, 2384, 2394, 2406, 2416, 2426, 2437,
  134. 2448, 2458, 2469, 2479,
  135.  
  136. 12, /* UPS 2ND DAY AIR - 48 STATES */
  137. 300, 400, 500, 600, 650, 750, 850, 950, 1050,
  138. 1150, 1250, 1350, 1450, 1550, 1650, 1750, 1850,
  139. 1950, 2000, 2100, 2200, 2300, 2400, 2500, 2600,
  140. 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400,
  141. 3500, 3600, 3650, 3750, 3850, 3950, 4050, 4150,
  142. 4250, 4350, 4450, 4550, 4650, 4750, 4850, 4950,
  143. 5050, 5050, 5100, 5100, 5150, 5150, 5200, 5200,
  144. 5250, 5250, 5300, 5300, 5350, 5350, 5350, 5400,
  145. 5400, 5450, 5450, 5500, 5500,
  146.  
  147. 14, /* UPS 2ND DAY AIR - ALASKA METRO & HAWAII */
  148. 500, 650, 750, 900, 1000, 1150, 1250, 1400, 1500,
  149. 1650, 1750, 1850, 1950, 2050, 2200, 2300, 2400,
  150. 2500, 2600, 2750, 2850, 2950, 3100, 3200, 3300,
  151. 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100,
  152. 4200, 4300, 4400, 4500, 4550, 4600, 4650, 4700,
  153. 4750, 4800, 4850, 4950, 5050, 5150, 5250, 5350, 
  154. 5450, 5550, 5600, 5650, 5700, 5750, 5800, 5850, 
  155. 5900, 5950, 6000, 6050, 6050, 6100, 6100, 6150, 
  156. 6150, 6200, 6200, 6250, 6250,
  157.  
  158. 15, /* UPS 2ND DAY AIR PUERTO RICO */
  159. 600, 700, 800, 900, 1000, 1100, 1200, 1300,
  160. 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 
  161. 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900,
  162. 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 
  163. 3800, 3900, 4000, 4050, 4150, 4250, 4350, 4450, 
  164. 4500, 4550, 4600, 4700, 4800, 4900, 5000, 5100, 
  165. 5200, 5300, 5300, 5350, 5350, 5400, 5400, 5450, 
  166. 5450, 5500, 5500, 5550, 5550, 5600, 5600, 5600, 
  167. 5650, 5650, 5700, 5700, 5750, 5750,
  168.  
  169. 16, /* UPS 2ND DAY AIR - ALASKA RURAL */
  170. 1250, 1350, 1450, 1550, 1650, 1750, 1900, 2000, 
  171. 2100, 2200, 2250, 2350, 2450, 2600, 2700, 2800, 
  172. 2900, 3000, 3100, 3250, 3350, 3450, 3550, 3650, 
  173. 3750, 3900, 4000, 4100, 4200, 4300, 4400, 4550, 
  174. 4650, 4750, 4850, 4950, 5050, 5150, 5250, 5350, 
  175. 5450, 5550, 5650, 5750, 5900, 6000, 6100, 6200, 
  176. 6300, 6400, 6450, 6450, 6500, 6550, 6550, 6600, 
  177. 6600, 6650, 6650, 6700, 6700, 6750, 6750, 6800, 
  178. 6850, 6850, 6900, 6900, 6950, 6950,
  179.  
  180. 22, /* UPS 1ST DAY AIR - 48 STATES */
  181. 1150, 1250, 1350, 1450, 1550, 1650, 1800, 1900, 
  182. 2000, 2100, 2200, 2300, 2400, 2550, 2650, 2750, 
  183. 2850, 2950, 3050, 3200, 3300, 3400, 3500, 3600, 
  184. 3700, 3850, 3950, 4050, 4150, 4250, 4350, 4500, 
  185. 4600, 4700, 4800, 4900, 5000, 5100, 5250, 5350, 
  186. 5450, 5550, 5650, 5750, 5900, 6000, 6100, 6200, 
  187. 6300, 6400, 6450, 6450, 6500, 6550, 6550, 6600, 
  188. 6600, 6650, 6650, 6700, 6700, 6750, 6750, 6800, 
  189. 6850, 6850, 6900, 6900, 6950, 6950,
  190.  
  191. 24, /* UPS 1ST DAY AIR - ALASKA & HAWAII */
  192. 1300, 1450, 1550, 1700, 1800, 1900, 2050, 2150,
  193. 2300, 2400, 2500, 2600, 2700, 2850, 3000, 3100,
  194. 3200, 3300, 3400, 3550, 3650, 3750, 3850, 3950,
  195. 4050, 4200, 4300, 4400, 4500, 4600, 4700, 4850,
  196. 4950, 5050, 5150, 5250, 5350, 5450, 5600, 5700,
  197. 5800, 5900, 6000, 6100, 6250, 6350, 6450, 6550,
  198. 6650, 6750, 6800, 6800, 6850, 6900, 6900, 6950,
  199. 6950, 7000, 7000, 7050, 7050, 7100, 7100, 7150,
  200. 7200, 7200, 7250, 7250, 7300, 7300,
  201.  
  202. 25, /* UPS 1ST DAY AIR - PUERTO RICO */
  203. 1500, 1600, 1750, 1850, 1950, 2050, 2200, 2350,
  204. 2450, 2550, 2650, 2750, 2850, 3000, 3100, 3200,
  205. 3300, 3400, 3500, 3650, 3750, 3850, 3950, 4050,
  206. 4150, 4300, 4400, 4500, 4600, 4700, 4850, 5000,
  207. 5100, 5200, 5300, 5400, 5500, 5600, 5750, 5850,
  208. 5950, 6050, 6150, 6250, 6400, 6500, 6600, 6700,
  209. 6800, 6900, 6950, 6950, 7000, 7050, 7050, 7100,
  210. 7100, 7150, 7150, 7200, 7200, 7250, 7250, 7300,
  211. 7350, 7350, 7400, 7400, 7450, 7450
  212. } ;
  213.  
  214. typedef struct trade_mark {
  215.     char    mk[90];
  216.     } trade_mark;
  217.     
  218. trade_mark mrk = {" UPS_Charge XFCN v1.0 Copyright 1988 by Sam Thornton * PO Box 123 * Fairfield NE 68938 "};
  219.  
  220. #define CHARGE_LENGTH (sizeof(charge_table) / sizeof(struct _chgs))
  221.  
  222. /* =================================================================== */    
  223. /*                               MAIN PROCEDURE                          */
  224. /* =================================================================== */
  225.  
  226. pascal void main (paramPtr)
  227. XCmdBlockPtr paramPtr;
  228.  
  229. {
  230.     char                _cost[256];
  231.     Handle                answer;
  232.     register int        d_cost;
  233.     register int        f_zone;
  234.     register int        weight;
  235.     
  236.     RememberA0();
  237.     SetUpA4();
  238.     
  239.     f_zone = atoi(*(paramPtr->params[0])); /* save the zone number */
  240.     
  241.     /* round fractional weights up to next even lb.,
  242.        per UPS/FEX schedules */
  243.     strcpy(_cost, "round(");
  244.     strcat(_cost, *(paramPtr->params[1]));
  245.     strcat(_cost, " + .49999)");
  246.     CtoPstr(_cost);
  247.     answer = EvalExpr(paramPtr, _cost);
  248.     weight = atoi(*answer);
  249.     DisposHandle(answer);
  250.     
  251.     /* sanity checks & evaluation */
  252.     if (weight < 1 || weight > 70) goto PANIC;
  253.     d_cost = FreightCharge(f_zone, (int)weight);
  254.     if (d_cost == -1) goto PANIC;
  255.     
  256.     /* format the return */
  257.     stci_d(_cost, d_cost, 7);
  258.     f_zone = strlen(_cost);
  259.     _cost[f_zone + 1] = '\0';
  260.     _cost[f_zone] = _cost[f_zone - 1];
  261.     _cost[f_zone - 1] = _cost[f_zone - 2];
  262.     _cost[f_zone - 2] = '.';
  263.     paramPtr->returnValue = NewHandle(f_zone + 2);
  264.     strcpy( *paramPtr->returnValue, _cost);
  265.     goto NOPANIC;
  266.     
  267. PANIC:
  268.     SysBeep(1);
  269. NOPANIC:
  270.     RestoreA4(); 
  271.     return;
  272. }
  273.  
  274. /* =================================================================== */
  275. /* function to return a FREIGHT charge, given <f_zone>,<weight>          */
  276. /* =================================================================== */
  277.  
  278. int FreightCharge(f_zone,weight)
  279. register int f_zone, weight;
  280. {
  281.     register int i,k;
  282.     k = CHARGE_LENGTH;
  283.     
  284.     /* since there are so few main entries, we can do a simple
  285.        serial search without losing too much time */
  286.     
  287.     for (i = 0; i < k; i++) {
  288.         if (charge_table[i]._charge[0] == f_zone)
  289.             return(charge_table[i]._charge[weight]);
  290.     }
  291.     return(-1); /* our error code for a bad zone number */
  292. }
  293.